def textCounts (content):
    my_counts = {}
    # 遍历我的列表值
    for value in content:
        # 如果值在我的计数对象中出现了
        if value in my_counts:
            # 对象中属性为value，其次数加1
            my_counts[value] += 1
        else:
            # 对象中没有这个值为属性的，次数为1
            my_counts[value] = 1
    return my_counts
# 导入os
import os
file_path = ".//demo.txt"
if os.path.exists(file_path):
    try:
        with open(file_path, "r", encoding="utf-8") as f:
            content = f.read().strip()
            content = content.split()
            print(textCounts(content))
    except UnicodeDecodeError:
        print("编码错误：请确认文件编码格式")
else:
    print("文件不存在")